package cool.tsy.emos.wx.task;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @author: hongxuan.wang
 * @date: Created in 2021/11/16 20:30
 * @description: 异步发送邮件任务
 * @mail: 1443424326@qq.com
 */
@Scope("prototype")
@Component
public class EmailTask implements Serializable {

    private final JavaMailSender javaMailSender;

    @Value("${emos.email.system}")
    private String mailbox;

    public EmailTask(JavaMailSender javaMailSender) {
        this.javaMailSender = javaMailSender;
    }

    @Async
    public void sendAsync(SimpleMailMessage message) {
        message.setFrom(mailbox);
        javaMailSender.send(message);
    }

}
